//
//  ZYStateImp.m
//  DesignMode
//
//  Created by wangzhipan on 2024/10/31.
//

#import "ZYStateImp.h"

@implementation ZYNetworkOpen

+ (instancetype)sharedInstance
{
    static id _instance = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _instance = [[self alloc] init];
    });
    return _instance;
}

- (void)operation1
{
    //do something...
    self.next = [ZYNetworkClose sharedInstance];
    NSLog(@"%s", __func__);
}

- (void)operation2
{
    //do...
    self.next = [ZYNetworkConnect sharedInstance];
    NSLog(@"%s", __func__);
}

- (void)operation3
{
    //do...
    self.next = [ZYNetworkOpen sharedInstance];
    NSLog(@"%s", __func__);
}
@end

@implementation ZYNetworkClose
- (void)operation1
{
    //do something...
    self.next = [ZYNetworkOpen sharedInstance];
    NSLog(@"%s", __func__);
}

- (void)operation2
{
    //do...
    self.next = [ZYNetworkClose sharedInstance];
    NSLog(@"%s", __func__);
}

- (void)operation3
{
    //do...
    self.next = [ZYNetworkConnect sharedInstance];
    NSLog(@"%s", __func__);
}

@end


@implementation ZYNetworkConnect
- (void)operation1
{
    //do something...
    self.next = [ZYNetworkOpen sharedInstance];
    NSLog(@"%s", __func__);
}

- (void)operation2
{
    //do....
    self.next = [ZYNetworkClose sharedInstance];
    NSLog(@"%s", __func__);
}

- (void)operation3
{
    self.next = [ZYNetworkConnect sharedInstance];
    NSLog(@"%s", __func__);
}
@end



@implementation ZYStateMainPage
- (instancetype)initWithState:(id<INetworkState>)state
{
    if (self = [super init]) {
        self.state = state;
    }
    return self;
}

- (void)operation1
{
    [self.state operation1];
    self.state = self.state.next;
}
- (void)operation2
{
    [self.state operation2];
    self.state = self.state.next;
}
- (void)operation3
{
    [self.state operation3];
    self.state = self.state.next;
}
@end
